package org.afk.sisy.gui.swing;

import java.sql.*;

import javax.swing.*;

import org.afk.sisy.db.*;
import org.afk.tools.log.*;

public class ShowMe implements Runnable
{
	private final PreferencesWrapper preferences = new PreferencesWrapper();
	private SisyGuiApp components;
	private final JobDataBase sisyJobDb;

	@Override
	public void run()
	{
		components = new SisyGuiApp(preferences, sisyJobDb);
		components.show();
	}

	public static void main(final String[] args)
	{
		final JobDataBase sisyJobDb = new JobDataBase();
		final Runnable me = new ShowMe(sisyJobDb);

		try
		{
			sisyJobDb.open();
			SwingUtilities.invokeAndWait(me);
		}
		catch (final Throwable t)
		{

			JOptionPane.showMessageDialog(null, "Error while starting Sisy: \r\n" + StringFactory.toString(t));
		}
		finally
		{
			try
			{
				sisyJobDb.close();
			}
			catch (final SQLException e)
			{
				e.printStackTrace();
			}
		}

	}

	public ShowMe(final JobDataBase sisyJobDb)
	{
		super();
		this.sisyJobDb = sisyJobDb;
	}
}
